package com.bit.inmap;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class AchieveActivity extends Activity {
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_achieve);

		GridView grid = (GridView) findViewById(R.id.grid);
		grid.setAdapter(new ImageAdapter(this));

		grid.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View v,
					int position, long id) {
				// Toast.makeText(AchieveActivity.this, (position+1) +
				// "번째 그림 선택",
				// Toast.LENGTH_SHORT).show();
				Intent i = new Intent(getApplicationContext(),
						FullImageActivity.class);
				i.putExtra("id", position);
				startActivity(i);
			}
		});
	}
}

class ImageAdapter extends BaseAdapter {
	private Context mContext;
	public Integer[] picture = { 
			R.drawable.a, R.drawable.b, R.drawable.c,
			R.drawable.d, R.drawable.e, R.drawable.f, R.drawable.g,
			R.drawable.h };

	public ImageAdapter(Context c) {
		mContext = c;
	}

	public int getCount() {
		return picture.length;
	}

	public Object getItem(int position) {
		return picture[position];
	}

	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imageView = new ImageView(mContext);
		imageView.setImageResource(picture[position]);
		imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
		
		imageView.setLayoutParams(new GridView.LayoutParams(230, 230));
		return imageView;
	}
}
